# -*- coding: utf-8 -*-
#
# Copyright 2009 Vanderbilt University
# 
# Licensed under the Apache License, Version 2.0 (the "License"); 
# you may not use this file except in compliance with the License. 
# You may obtain a copy of the License at 
# 
#     http://www.apache.org/licenses/LICENSE-2.0 
# 
# Unless required by applicable law or agreed to in writing, software 
# distributed under the License is distributed on an "AS IS" BASIS, 
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
# See the License for the specific language governing permissions and 
# limitations under the License. 

from hornet.event import Event
from hornet.plugin import Plugin
from hornet.network import add_edge

def cause_error(*args, **kw):
    raise Exception, 'fake'
 
def get_edge(graph, nodeA, nodeB):
    for e in graph.edges(data=True):
        if e[0:2] == (nodeA, nodeB):
            return e 

def add_biedge(graph, nodeA, nodeB, **kwargs):
    add_edge(graph, nodeA, nodeB, **kwargs)
    add_edge(graph, nodeB, nodeA, **kwargs)
        
class FakeEvent(Event):
    pass

class FakePlugin(Plugin):
    def __init__(self, accepted_events=FakeEvent):
        self._accepted_events = accepted_events
        self.setup_called = False
        self.teardown_called = False
        self.notify_called = False
        self.notify_event = None
        
    def setup(self):
        self.setup_called = True

    def teardown(self):
        self.teardown_called = True
        if self.teardown_error:
            cause_error()
    
    def notify(self, event):
        """some docstring"""
        self.notify_event = event
        self.notify_called = True
    
    def accepted_events(self):
        return self._accepted_events

class FakeConfig(object):
    output_dir = 'folder'

class FakeApplication(object):
    config = FakeConfig()
